package com.ruoyi.project.wenyanwen.sentence.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.wenyanwen.sentence.domain.Sentence;
import com.ruoyi.project.wenyanwen.sentence.service.ISentenceService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 诗词名句Controller
 * 
 * @author shixiangwen
 * @date 2020-08-05
 */
@Controller
@RequestMapping("/wenyanwen/sentence")
public class SentenceController extends BaseController
{
    private String prefix = "wenyanwen/sentence";

    @Autowired
    private ISentenceService sentenceService;

    @RequiresPermissions("wenyanwen:sentence:view")
    @GetMapping()
    public String sentence()
    {
        return prefix + "/sentence";
    }

    /**
     * 查询诗词名句列表
     */
    @RequiresPermissions("wenyanwen:sentence:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Sentence sentence)
    {
        startPage();
        List<Sentence> list = sentenceService.selectSentenceList(sentence);
        return getDataTable(list);
    }

    /**
     * 导出诗词名句列表
     */
    @RequiresPermissions("wenyanwen:sentence:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Sentence sentence)
    {
        List<Sentence> list = sentenceService.selectSentenceList(sentence);
        ExcelUtil<Sentence> util = new ExcelUtil<Sentence>(Sentence.class);
        return util.exportExcel(list, "sentence");
    }

    /**
     * 新增诗词名句
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存诗词名句
     */
    @RequiresPermissions("wenyanwen:sentence:add")
    @Log(title = "诗词名句", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Sentence sentence)
    {
        return toAjax(sentenceService.insertSentence(sentence));
    }

    /**
     * 修改诗词名句
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Sentence sentence = sentenceService.selectSentenceById(id);
        mmap.put("sentence", sentence);
        return prefix + "/edit";
    }

    /**
     * 修改保存诗词名句
     */
    @RequiresPermissions("wenyanwen:sentence:edit")
    @Log(title = "诗词名句", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Sentence sentence)
    {
        return toAjax(sentenceService.updateSentence(sentence));
    }

    /**
     * 删除诗词名句
     */
    @RequiresPermissions("wenyanwen:sentence:remove")
    @Log(title = "诗词名句", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sentenceService.deleteSentenceByIds(ids));
    }
}
